package su.myspringapps.online_school_learning_spring_data_jpa.entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import javax.persistence.*;
import java.util.Objects;

/**
 * Класс Account
 * <p/>
 * TODO: need class description here
 * <p/>
 *
 * @author petr.mikhailin
 * created 19.06.2024 10:40
 */
@Entity
@Table(name = "accounts")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Account {
    @Id
    @GeneratedValue(generator = "account-sequence-generator")
    @GenericGenerator(
            name = "account-sequence-generator",
            strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
            parameters = {
                    @Parameter(name = "sequence_name", value = "account_seq")
            }
    )
    private int id;

    private String login;

    private String password;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Account accounts = (Account) o;

        if (id != accounts.id) return false;
        if (!Objects.equals(login, accounts.login)) return false;
        return Objects.equals(password, accounts.password);
    }
}
